import type { ConsultType } from '@/enums'
import type { ConsultIllness, PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 定义问诊信息的全局数据
    const consult = ref({} as PartialConsult)

    // 设置问诊类型
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }

    // 设置选中医院类型
    const setIllnessType = (illnessType: 0 | 1) => {
      consult.value.illnessType = illnessType
    }

    // 设置科室
    const setDep = (depId: string) => {
      consult.value.depId = depId
    }

    // 设置病情描述
    const setIllness = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }

    // 设置患者
    const setPatient = (patientId: string) => {
      consult.value.patientId = patientId
    }

    // 设置优惠券
    const setCoupon = (couponId?: string) => {
      consult.value.couponId = couponId
    }

    // 清空数据
    const clear = () => {
      consult.value = {}
    }

    return { consult, setType, setIllnessType, setDep, setIllness, setPatient, setCoupon, clear }
  },
  {
    persist: true
  }
)
